package registnet.cpm.util;

import registnet.cpm.Project;
import registnet.cpm.Node;

/**
 * A visitor implementation which computes the late start
 * and late finish of a node.
 */
public class LateStartLateFinishImp implements IVisitor {

	@Override
	public void visit(Project activity, Node node) {
		if(!activity.hasSuccessor(node)){
			node.setLateFinish(activity.getProjectDuration());
			node.setLateStart(node.getLateFinish() - node.getValue());
		}else{
			node.setLateFinish(32767);
			for(int i=0; i<activity.getSuccessors(node).size(); i++)
				if(node.getLateFinish() > activity.getSuccessors(node).get(i).getLateStart())
					node.setLateFinish(activity.getSuccessors(node).get(i).getLateStart());
			node.setLateStart(node.getLateFinish()-node.getValue());
		}
	}

}
